<template>
  <div class="page">
    <headerbar>{{ title }}
      <span @click="add()" class="head-btn" slot="btn"
      ><strong>+</strong>申请</span>
    </headerbar>
    <section style="overflow: hidden;">
      <div v-if="tabIndex == 0" id="partake" class="mui-active">
        <div class="d-scroll list-text" style="">
          <fetchData
            v-if="isLoading"
            :loading="isLoading"
            :data="swipeData"
          ></fetchData>
          <cube-scroll
            ref="scroll"
            :options="options"
            @pulling-up="onPullingUp"
            @pulling-down="onPullingDown"
          >
            <cube-swipe  :key="newmemorabilias">
              <transition-group name="swipe" tag="div">
                <div class="" v-for="(data, index) in swipeData" :key="data.consultId">
                  <cube-swipe-item ref="swipeItem" :btns="data.btns" @btn-click="receiveAction" :index="index">
                    <div @click="goDetail(data)" class="item">
<!--                      <div class="name">
                        <span>主题：</span>{{ data.theme }}
                        <span
                          class="pdl-3 color-red"
                          @click.stop="cancel(data,index)"
                        ><i class="pdh-2"></i>
                            <span class="btn-text">删除</span></span>
                      </div>-->
                      <div class="item-content-state">
                        <div class="left">
                          项目名称：<span>{{ data.projectName }}</span>
                        </div>
                        <div class="look-more">查看详情&nbsp;>&nbsp;></div>
                      </div>
                      <div  class="jianjie-my"><span>联系人：</span>{{ data.consultUser }}</div>
                      <div  class="jianjie-my"><span>联系电话：</span>{{ data.consultTelephone }}</div>
                    </div>
                  </cube-swipe-item>
                </div>
              </transition-group>
            </cube-swipe>
            <!-- <div class="text-center no-data" v-if="!isLoading && swipeData.length===0">
              <img src="../../../../static/images/no_data.png" alt="">
              <p>暂无数据</p>
            </div> -->
            <!-- W noData -->
            <noData v-if="!isLoading && swipeData.length === 0"></noData>
            <onBottom v-else-if="onBottom"></onBottom>
          </cube-scroll>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
  import tools from "@/utils/tools";
  import api from "@/common/config/api";
  import loginService from "@/service/loginService";
  import moment from "moment";
  export default {
    name: "settlementList",
    data() {
      return {
        isLoading: true,
        fn: tools,
        count:0,
        options: {
          pullUpLoad: true,
          scrollbar: false,
          pullDownRefresh: {
            threshold: 90,
            stop: 0,
            txt: ' '
          },
        },
        onBottom: false, // W onBottom
        launchOptions: {
          pullUpLoad: true,
          scrollbar: false,
          pullDownRefresh: {
            threshold: 90,
            stop: 0,
            txt: ' '
          },
        },
        selectList:[],//下拉框
        getDict:[],
        objectsName: "",
        swipeData: [],
        launchSwipeData: [],
        infinite: true,
        pageIndex: 1,
        launchPageIndex: 1,
        tabIndex: 0,
        fromType: "",
        subType: "",
        title: "申请列表",
        roleData: "",
        showTypes: "1",
        newmemorabilias:'',
        selectChange:'',
        selectChangeOne:'',
        themeLaunch:'',
        theme:'',
        jlyyTime:0,
      };
    },
    created() {
      this.loadPartakeData();
    },
    methods: {
      goDetail(data) {
        this.$router.push({ path: `/settlementAdd`,name:'settlementAdd', params:{form: data,status:false} });
      },
      fontColor(status) {
        let colorName = {
          未签到: "color-red",
          未开始: "color-tip",
          请假: "color-green",
          已参与: "color-green",
          已结束: "color-tip",
          未参加: "color-red",
        };
        console.log(colorName[status.statusName]);
        return colorName[status.statusName];
      },
      loadPartakeData() {
        this.isLoading = true;
        this.onBottom = false;
        this.tabIndex = 0;
        let data = {
          "pageNo":  this.pageIndex,
          "pageSize": 20,
        }
        loginService.postConsultInfoList(data).then((res) => {
          this.isLoading = false;
          if (res.code !== 0) {
            this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate();
            return tools.tip(res.message);
          }
          this.pageIndex++;
          if (res.code === 0 && res.data.length < 1) {
            this.onBottom = true
            this.options.pullUpLoad = false
            return
          }
          res.data.forEach((v, i) => {
            v.btns = [];
            v.btns.push({
              receiveAction: "receiveDeleteItem",
              text: "删除",
              color: "#ec5563",
            });
          });
          this.swipeData = this.swipeData.concat(res.data);
          console.log('this.swipeDatathis.swipeData',this.swipeData);
          this.count = res.count
          setTimeout(() => {
            this.$refs.scroll.forceUpdate &&
            this.$refs.scroll.forceUpdate(true, false);
            this.options.isPullUpLoad = false;
          }, 100);
        });
      },
      receiveAction(btn, index) {
        let item = this.swipeData[index];
        this[btn.receiveAction](item, index);
      },
      receiveDeleteItem(item, index) {
        this.alertDialog(item, index, this.swipeData);
      },
      action(btn, index) {//已完成删除按钮
        let item = this.launchSwipeData[index];
        this[btn.action](item, index);
      },
      onPullingUp() {
        console.log("onPullingUp");
        this.loadPartakeData();
      },
      onPullingDown() {
        this.options.pullUpLoad = true
        this.onBottom = false
        this.swipeData = []
        console.log('onPullingDown')
        this.pageIndex = 1
        this.loadPartakeData()
      },
      add() {
        this.$router.push({
          path: `/settlementAdd`,
        });
      },
      alertDialog(item, index, data) {
        let _this = this;
        this.$createDialog({
          type: "confirm",
          icon: "",
          title: "温馨提示",
          content: "确定删除？",
          confirmBtn: {
            text: "确定",
            active: true,
            disabled: false,
            href: "javascript:;",
          },
          cancelBtn: {
            text: "取消",
            active: false,
            disabled: false,
            href: "javascript:;",
          },
          onConfirm: () => {
            _this.deleteItem(item, index, data);
          },
          onCancel: () => {},
        }).show();
      },
      deleteItem(item, index, data) {
        console.log("-------------item.msgId={}", item);
        // this.tools.showLoading();
        this.fetchService.postDeleteConsultInfo(item.consultId).then((res) => {
          this.tools.hideLoading();
          if (res.code !== 0) {
            this.newmemorabilias = Date.now();
            return this.tools.tip(res.message);
          }
          data.splice(index, 1);
          this.tools.tip("删除成功");
          this.newmemorabilias = Date.now();
        });
      },
    },
  };
</script>

<style scoped lang="scss">
  @import "@/common/stylus/moon.scss";
  .list-text .item {
    font-size: $defaultFontSize;
    .name {
      font-weight: bolder;
      padding-bottom: 10px;
    }
    .color-red{
      position: absolute;
      right: 16%;
    }
    span {
      font-weight: inherit;
      font-size: inherit;
    }
  }
  .tab li.active span {
    background: #fff;
    display: inline-block;
    color: #e20001;
    text-align: center;
    border-radius: .10667rem;
    font-weight: bold;
    font-size: 16PX;
  }
  .head-btn{
    font-size: 14PX;
    >strong{
      font-size: 18PX;
      margin-right: 3px;
    }
  }
  .tab{
    margin-bottom: .16667rem;
  }
  .cube-swipe-item{
    margin: 0.2rem;
    .item{
      border-radius: 0.2rem;
      .item-content-state{
        display: flex;
        justify-content: space-between;
        .left{
          max-width: 60%;
        }
        .look-more{
        }
      }
    }
  }
  .live-msg-wrap {
    .card-foot {
      font-size: $titleFontSize;
      padding-right: 0;
      padding-bottom: 0;
      .btn-text {
        white-space: nowrap;
        border-radius: pxToRem(10px);
        line-height: pxToRem(44px);
        padding: 0 pxToRem(10px);
        font-weight: 400;
        text-align: center;
        border: 1px solid $theme-color;
      }
    }
  }
  .select-box {
    width: 100%;
    height: 90px;
    background: #ffffff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 2%;
    .state-box {
      position: relative;
      img {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        right: 16px;
        width: 20px;
      }
      .select {
        width: 2rem;
        height: 50px;
        line-height: 50px !important;
        padding-top: 0;
        padding-bottom: 0;
        margin-bottom: 0;
        background: #ffffff;
        border: 1px solid #9a9a9a !important;
        border-radius: 10px;
      }
    }
    .btn-box {
      position: relative;
      width: 60%;
      .select-btn {
        width: 100%;
        height: 50px;
        background: #ffffff;
        border: 1px solid #9a9a9a;
        border-radius: 10px;
        margin-bottom: 0;
        padding: 10px 10px 10px 50px;
      }
      img {
        position: absolute;
        width: 25px;
        top: 50%;
        transform: translateY(-50%);
        left: 15px;
      }
    }

    span {
      font-size: 14PX;
      color: #e20002;
    }
  }
  .d-scroll{
    height: calc(100vh - 0.5rem - .66667rem);
  }
</style>
